package com.jnpc.spark.project.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangqiang on 2018/1/15 0015.
 */
public class NLPUtil {

	public static void main(String[] args) {


/*
        try {
			String line=null;
			BufferedReader br = null;
			try {
				br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\data\\nlpdata4.csv"),"GBK"));
			} catch (UnsupportedEncodingException e1) {
				e1.printStackTrace();
			}
			try {
				while((line=br.readLine())!=null){
					
					String[] ll=line.split(",");
					System.out.println("string="+ll[1]);
				 GetFinal(ll[1]);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		*/
	}

    public  String getFenciResult(String content){
        HttpClientUtil httpClientUtil= new HttpClientUtil();
        String httpOrgCreateTest =  "http://10.23.16.200:12345/ltp";
        Map<String,String> createMap = new HashMap<String,String>();
        createMap.put("s",content);
        createMap.put("x","n");
        createMap.put("t","ws");

        String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,createMap, "utf-8");

        JSONArray jsonarray1=JSON.parseArray(httpOrgCreateTestRtn);
        String xx1=jsonarray1.getString(0);
        JSONArray jsonarray2=JSON.parseArray(xx1);
        String xx2=jsonarray2.getString(0);
        List<Result> result=JSON.parseArray(xx2, Result.class);

        StringBuilder sb=new StringBuilder("");
        for(int i=0;i<result.size();i++){
            sb.append(result.get(i).getCont()).append("|");
      /* if(result.get(i).getArg().size()>0){
           for(int j=0;j<result.get(i).getArg().size();j++){
           System.out.println("result.get("+i+").getArg("+j+")="+j+result.get(i).getArg().get(j).toString());
           }
        }*/
        }
        return sb.substring(0,sb.length()-1);
    }



}
